package com.zhouchao.mvp2.mvp;

import android.util.Log;

import java.lang.ref.WeakReference;

/**
 * 描述：
 * zhougan
 * 2019/2/28
 **/
public class BasePresenter<V extends IView> implements IPresenter<V> {
    private static final String TAG = ">>>"+BasePresenter.class.getSimpleName();
    private WeakReference<V> mView;

    @Override
    public void attachView(V view) {
        Log.i(TAG, "attachView: 关联View");
        mView = new WeakReference<>(view);

    }

    @Override
    public V getView() {
        if(mView==null){
            return null;
        }
        return mView.get();
    }

    @Override
    public void onDestroyView() {
        Log.i(TAG, "onDestroyView: 销毁View");
        mView.clear();
        mView=null;
    }

    @Override
    public boolean isAttach() {
        return mView!=null && getView()!=null;
    }
}
